﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.ViewModels.ProductTypePropertyManageViewModels>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Loại thuộc tính cho sản phẩm
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function TypeProdpertiesSelect(dropDownList) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;

            if (document.all || document.getElementById)
                document.getElementById('HiddenTypePropertiesID').value = selects;
            else
                document.getElementById('HiddenTypePropertiesID').setAttribute("value", selects);
        }
        function StatusSelect(dropDownList) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;

            if (document.all || document.getElementById)
                document.getElementById('HiddenStatus').value = selects;
            else
                document.getElementById('HiddenStatus').setAttribute("value", selects);
        }
        function SaveStatus(dropDownList, id) {
            var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selects = selectedReport.value;
            actionChangeStatus(selects, id);
        }
        function actionChangeStatus(values, id) {
            var url = '<%=Url.Action("","Stock")%>' + '/' + id + '/' + values;
            $.getJSON(url, function (outStr) {
                $('#statusID' + id).val(outStr);
            });
        }
     </script>

       <% using (Html.BeginForm("ProductTypeProperties", "Stock", FormMethod.Post, new { id = "sendFileForm", enctype = "multipart/form-data" }))
   {%>
    <div class="clear"></div>
    <div class="column full">
    <div class="box ">
		<h2 class="box-header">	Stock Manage : <%=Model.Product.ProductName %></h2>
		<div class="box-content">
                    
                    <div id="grid">	
                               		    						               
				                <table class="display" >
                                <thead>
					                <tr>
						               
                                        <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "TypePropertiesID") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "TypePropertiesID")%>">
								                Loại thuộc tính</a>
                                        </th>	                                 						                

                                        <th>
                                            <a href="#" class="<%= StockController.GetGridThClass(ViewData, "Status") %>" 
										                onclick="<%= StockController.GetGridThOnClick(ViewData, "Status")%>">
								                Trạng thái</a>
                                        </th>
                                                                              
                                        <th colspan="2"></th>                                       
					                </tr>
                                    
                                    <tr>
                                        <td>
                                            <%--<%=Html.DropDownList("TypeProperty", (SelectList)ViewData["ListTypeProduct"],"--Choose type property--", new { onchange = "TypeProdpertiesSelect(this);" })%>--%>
                                            <%=Html.HiddenFor(m=>m.HiddenTypePropertiesID) %>
                                        </td>
                                        <td>
                                            <%--<%
                                                List<SelectListItem> statusSearch = new List<SelectListItem>();
                                                statusSearch.AddRange(new SelectListItem[] { 
                                                new SelectListItem{ Text = "--Choose status--",Value="-1"},    
                                                new SelectListItem{ Text = "Active", Value = "1" },
                                                new SelectListItem{ Text = "unActive", Value = "0" }
                                                });
                                                %>

                                                <%=Html.DropDownListFor(m => m.Status, statusSearch, new { onchange = "StatusSelect(this);" })%> --%>
                                                <%=Html.HiddenFor(m=>m.HiddenStatus) %>
                                        </td>
                                        <td colspan="2">
                                            <%
                                                    string returnUrl = Request.Url.ToString();
                                                    //string StrTypePropertyID = Request.Form.GetValues("HiddenTypePropertiesID") != null ? Request.Form.GetValues("HiddenTypePropertiesID")[0] : "";
                                                    //string StrStatus = Request.Form.GetValues("Status") != null ? Request.Form.GetValues("Status")[0] : "";
                                                    string te1 = Model.HiddenStatus;
                                                    string te2 = Model.HiddenTypePropertiesID;
                                                 %>

                                                <%= Html.ActionLink("Thêm mới loại thuộc tính cho sản phẩm", "AddProductTypeProperties", "Stock", new { id = Model.Product.ProductID }, new { @Class = "button themed" })%>
                                                
                                        </td>
                                    </tr>
                                </thead>
                                <% if (Model.ProductTypePropertyItem.Count() == 0)
                                   { %>
			                        <tbody>
                                        <tr>
                                            <td colspan="9">
                                                Không có loại thuộc tính nào cho sản phẩm này
                                            </td>
                                        </tr>
                                    </tbody>
		                        <% } else { %>
                                <tbody>
					                <% foreach (var item in Model.ProductTypePropertyItem){ %>
				    
						                <tr>						                
							                <td>
								                <%
                                                    string nameType = "";
                                                    var type = StockModel.GetTypePropertiesById((int)item.TypePropertiesID);
                                                    nameType = type.TypePropertiesName;
                                                %>
                                                <%=nameType %>
							                </td>
							
                                            <td>
                                               <%
                                                    bool newStatus=false;
                                                    if (item.Status == 0)
                                                    {
                                                        newStatus=true;
                                                    }
                                                    else if (item.Status == 1)
                                                    {
                                                        newStatus=false;
                                                    }
                                                %>
                                                <%
                                                List<SelectListItem> statusDrop = new List<SelectListItem>();
                                                statusDrop.AddRange(new SelectListItem[] { 
                                                new SelectListItem{Selected=newStatus, Text = "Kích hoạt", Value = "1" },
                                                new SelectListItem{Selected=newStatus, Text = "Không kích hoạt", Value = "0" }
                                                });
                                                %>
                                              
                                               <%= Html.DropDownList("statusID" + item.ProductTypePropertiesID, statusDrop, new { onchange = "SaveStatus(this," + item.ProductTypePropertiesID + ")" })%>
                                            </td>
                                            
                                            <td>
                                                
                                                <%= Html.ActionLink("Xóa", "DeleteProductTypeProperty", new { id = item.ProductTypePropertiesID, returnUrl = returnUrl }, new { onclick = "return confirm('Bạn thực sự muốn xóa ?');" })%>
                                            </td>
						                </tr>
				    
					                <% } %>
					            </tbody>
                                <% } %>
				                </table>
			                <!-- data -->
                                <% if (Model.ProductTypePropertyItem.Count() > 0)
                                   { %>
			                       <% Html.RenderPartial("~/Views/Commont/Paging.ascx"); %>
		                        <% } %>
		                
	                </div>  <!-- grid -->	
                
               
	    </div>
	</div>
    <div class="clear"></div>
    </div>    
<% } %>
</asp:Content>
